package com.hrma.services.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.hrma.dao.OvertimeApplicationMapper;
import com.hrma.dao.OvertimeRecordMapper;
import com.hrma.entity.*;
import com.hrma.services.OvertimeRecordService;
import com.hrma.utils.UserUtil;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OvertimeRecordImpl implements OvertimeRecordService {
    private final OvertimeRecordMapper overtimeRecordMapper;

    public OvertimeRecordImpl(OvertimeRecordMapper overtimeRecordMapper, OvertimeApplicationMapper overtimeApplicationMapper) {
        this.overtimeRecordMapper = overtimeRecordMapper;
        this.overtimeApplicationMapper = overtimeApplicationMapper;
    }

    private final OvertimeApplicationMapper overtimeApplicationMapper;

    @Override
    public OvertimeRecordVO add(OvertimeRecordVO data) {
        data.setAuditorId(UserUtil.getUserId());
        overtimeRecordMapper.add(data);
        overtimeApplicationMapper.setState(data.getState(),data.getApplicationId());
        return data;
    }

    @Override
    public List<SelectResult> select() {
        return overtimeRecordMapper.select();
    }

    @Override
    public Page<OvertimeRecordVO> getList(OvertimeRecordDTO data) {
        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return overtimeRecordMapper.getList(data);
    }

    @Override
    public Page<OvertimeRecordVO> getPersonalList(OvertimeRecordDTO data) {
        data.setEmployeeId(UserUtil.getUserId());
        PageHelper.startPage(data.getPageNum(), data.getPageSize());
        return overtimeRecordMapper.getList(data);
    }


}
